package com.telecomyt.jwportal.activity.person;

import android.app.Activity;

import com.telecomyt.jwportal.activity.person.bean.PersonInfoBean;
import com.telecomyt.jwportal.base.BasePresenter;
import com.telecomyt.jwportal.http.RequestParams;
import com.telecomyt.jwportal.http.RetrofitManager;
import com.telecomyt.jwportal.http.base.BaseObserver;
import com.telecomyt.jwportal.http.base.RxHelper;
import com.telecomyt.jwportal.utils.ToastUtils;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;

/**
 * @author created by chengDa
 * @time 2020/8/31  15:21
 * @description
 */
public class PersonPresenter extends BasePresenter<PersonContract.Model, PersonContract.View> implements PersonContract.Presenter {
    public PersonPresenter(LifecycleProvider<ActivityEvent> provider) {
        super(provider);
    }

    @Override
    public void getPersonData(int userId, int tenantId) {
        getView().showLoading();
        RetrofitManager.getInstance()
                .getDefaultReq()
                .getPerson(new RequestParams().put("userId", userId).put("tenantId", tenantId).getBody())
                .compose(RxHelper.observableIOMain((Activity) getProvider()))
                .subscribe(new  BaseObserver<PersonInfoBean>() {
                    @Override
                    public void onSuccess(PersonInfoBean bean) {
                        getView().dismissLoading();
                        if (bean != null) {
                            getView().setPersonInfo(bean);
                        }
                    }

                    @Override
                    public void onFailure(Throwable e, String errorMsg) {
                        getView().dismissLoading();
                        ToastUtils.showShort(errorMsg);
                    }
                });

    }

    @Override
    protected PersonContract.Model creatModule() {
        return null;
    }
}
